<template>
	<view class="container">
		<!-- 钱包余额 -->
		<view class="balance-area">
			<view class="balance">
				<view>钱包余额 （元）</view>
				<view>{{ userInfo.amount/100 }}</view>
			</view>
			<view class="balance">
				<view>诚意金/招聘费 （元）</view>
				<view>{{ gold/100 }}</view>
			</view>
		</view>
		<!-- 操作 -->
		<view class="handle">
			<view @click="handleOpenPage(0)">
				<image src="/static/icon1/22.png" mode="aspectFill"></image>
				<text>我要充值</text>
			</view>
			<view @click="handleOpenPage(1)">
				<image src="/static/icon1/23.png" mode="aspectFill"></image>
				<text>我要提现</text>
			</view>
		</view>
		<view class="t-box-line">
			<view class="t-box-line-box">
				<view class="t-box-line-left">
					<view class="t-box-line-left-inner">
						<text>{{nowDateY}}年{{nowDateM}}月</text>
						<view class="t-box-line-left-inner-time">
							<xp-picker mode="ym" ref="picker" @confirm="confirm" />
						</view>
					</view>
				</view>
				<view class="t-box-line-right">
					<view class="t-box-line-right-left">
						<text>支出￥{{outAccount}}</text>
					</view>
					<view class="t-box-line-right-right">
						<text>收入￥{{inAccount}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 流水列表 -->
		<view class="flow-list">
			<view v-for="item in flowList" :key="item.id">
				<view>
					<view>{{ item.remark}}</view>
					<view>{{ item.createTime }}</view>
				</view>
				<view>
					<view :class="item.amount > 0 ? 'add' : 'reduce'">
						{{ item.amount > 0 ? `+${item.amount/100}` : item.amount/100 }}
					</view>
					<view v-if="item.type==12 && item.userDraw">
						<text v-if="item.checkText=='提现审核中'"
							style="background: #DB1211;padding: 2rpx 10rpx;color: #fff;border-radius: 4rpx;font-size: 20rpx; margin-right: 10rpx;">
							{{item.checkText}} </text>
						<text v-if="item.checkText=='提现成功'"
							style="background: #A2A2A2;padding: 2rpx 10rpx;color: #fff;border-radius: 4rpx;font-size: 20rpx; margin-right: 10rpx;">
							{{item.checkText}} </text> 包含服务费{{item.userDraw.amountys/100}}元
					</view>
					<view id="blackFontColor" v-if="item.type==13 && item.userDraw">
						<!-- <text>{{item.userDraw.remark.split('：')[1]}}</text> -->
						<view style="position: relative;margin-right: 80rpx;">提现审核未通过：
							<!-- <text style="color: #409EFF;"></text> -->
						</view>
						<view class="tips1" style="position: absolute;right:0;bottom:14%;z-index: 9;">
							<uni-tooltip :styleType4="1" :styleType="1" :styleType2="1" :styleType3="2"
								:content="item.userDraw.remark.split('：')[1]">
								<text style="color: #409EFF;">查看原因</text>
							</uni-tooltip>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 加载 -->
		<uni-load-more :status="hasFlag ? 'loading' : 'noMore'"></uni-load-more>
	</view>
</template>
<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'
	import xpPicker from '@/components/xp-picker/xp-picker'
	import moment from 'moment'
	moment.locale('zh-cn');
	export default {
		components: {
			uniLoadMore,
			xpPicker
		},
		data() {
			return {
				hasFlag: true, // 是否还有更多数据要加载
				amount: 5000, //
				userInfo: {
					user: {},
					params: {}
				}, //当前用户信息
				flowList: [], //资金流水
				gold: '', //诚意金
				flowObj: { //(type 0 资金 50 诚信值)
					type: 0,
					findDate: '',
					pageNum: 0,
					pageSize: 10,
				},
				nowDateY: moment(new Date().getTime()).format('YYYY'),
				nowDateM: moment(new Date().getTime()).format('MM'),
				inAccount: 0,
				outAccount: 0
			}
		},
		onLoad() {
			this.flowObj.findDate = this.nowDateY + '-' + this.nowDateM
			this.refresh()
		},
		methods: {
			async getTwater() {
				let res = await this.$fetch(this.$api.my_flow_static, this.flowObj, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.inAccount = res.data.inAccount
				this.outAccount = res.data.outAccount
			},
			async confirm(e) {
				this.nowDateY = e.value.split("-")[0]
				this.nowDateM = e.value.split("-")[1]
				this.flowObj.findDate = e.value
				this.flowObj.pageNum = 0
				this.flowList = []
				this.hasFlag = true
				this.my_flow()
				this.getTwater()
			},
			// 获取诚意金
			async get_user_sincerity_gold() {
				let res = await this.$fetch(this.$api.get_user_sincerity_gold, {}, 'POST')
				console.log('诚意金', res)
				if (res.code && res.msg != null) {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					return
				}
				this.gold = res.data ? res.data : 0
				// console.log('诚意金', res.data)
			},
			// 获取资金流水
			async my_flow() {
				if (!this.hasFlag) return // 说明已经没有更多啦

				++this.flowObj.pageNum
				let res = await this.$fetch(this.$api.my_flow, this.flowObj, 'POST')
				// console.log('获取资金流水', res)
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				uni.stopPullDownRefresh()
				// 拼接
				this.flowList = [...this.flowList, ...res.rows]
				this.hasFlag = this.flowList.length < res.total
			},
			// 打开内页面
			handleOpenPage(page) {
				if (page == 0) {
					uni.navigateTo({
						url: '/pages/prepaid/prepaid'
					})
				} else {
					uni.navigateTo({
						url: '/pages/cash-out/cash-out'
					})
				}
			},
			// 刷新
			refresh() {
				this.flowList = []
				this.hasFlag = true
				this.flowObj.pageNum = 0
				this.flowObj.pageSize = 10
				this.my_flow()
				this.getTwater()
			},
			async getCurrentUser() {
				let res = await this.$fetch(this.$api.get_current_user, {}, 'GET')
				// console.log('获取资金流水', res)
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.userInfo = res.data
			}
		},
		onShow() {
			this.getCurrentUser()
			this.get_user_sincerity_gold()
		},
		onReachBottom() {
			this.my_flow()
		},
		onPullDownRefresh() {
			//监听用户下拉动作，一般用于下拉刷新
			this.refresh()
		},
	}
</script>
<style lang="less">
	.container {
		&>.balance-area {
			display: flex;
			padding: 50rpx 0 60rpx;
			background-color: #FCC928;

			&>.balance {
				flex: 1;
				text-align: center;

				&>view:first-child {
					color: rgba(64, 33, 16, 0.70);
					margin-bottom: 20rpx;
					height: 40rpx;
				}

				&>view:last-child {
					font-size: 32px;
					height: 90rpx;
				}
			}
		}

		.t-box-line {
			width: 100%;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.t-box-line-box {
				width: 92%;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.t-box-line-left {
					width: 30%;
					// margin-left: 10rpx;
					height: 70rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.t-box-line-left-inner {
						font-size: 28rpx;
						position: relative;

						// 
						.t-box-line-left-inner-time {
							position: absolute;
							right: -25%;
							bottom: 6rpx;
							// border: 1px solid;
							display: flex;
							justify-content: center;
							align-items: center;
							// width: 100%;
							// height: 100rpx
						}
					}
				}

				.t-box-line-right {
					flex: 1;
					height: 70rpx;
					display: flex;
					justify-content: flex-end;
					align-items: center;

					// margin-right: 10rpx;
					.t-box-line-right-left {
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 26rpx;
						color: #A2A2A2;
					}

					.t-box-line-right-right {
						display: flex;
						justify-content: center;
						align-items: center;
						margin-left: 100rpx;
						font-size: 26rpx;
						color: #A2A2A2;
					}
				}
			}
		}

		&>.handle {
			padding: 30rpx 0;
			display: flex;
			background-color: #FFFFFF;

			&>view {
				height: 40rpx;
				width: 375rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 10rpx;
				}
			}

			&::before {
				content: "";
				position: absolute;
				left: 374rpx;
				width: 2rpx;
				height: 40rpx;
				background: #F2F2F2;
				border-radius: 0.5px;
			}
		}

		&>.flow-list {
			background-color: #FFFFFF;
			min-height: calc(100vh - 420rpx);

			&>view {
				height: 113rpx;
				width: 690rpx;
				position: relative;
				padding-left: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				&>view {
					// height: 60rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					&>view:first-child(1) {
						color: #000000;
						margin-bottom: 10rpx;
					}

					&>view:last-child {
						font-size: 12px;
						color: #A2A2A2;
					}
				}

				&>view:last-child {
					align-items: flex-end;

					&>.add {
						font-weight: bold;
						font-size: 17px;
						color: #4E9800;
					}

					&>.reduce {
						font-weight: bold;
						font-size: 17px;
						color: #C9281C;
					}
				}

				&::before {
					content: "";
					position: absolute;
					top: 113rpx;
					width: 690rpx;
					height: 2rpx;
					background: #F2F2F2;
					border-radius: 1px;
				}
			}
		}
	}

	#blackFontColor {
		color: #000000;
		width: 300rpx;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>